home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / SprocketExamples / GlyphaIV / GlyphaIV Sources / G4SetUpTakeDown.c < prev    next >
Encoding:
Text File  |  1998-07-14  |  24.8 KB  |  697 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        G4SetUpTakeDown.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (sjb)    Steve Bollinger
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <3>      7/1/98    sjb        Update to CWPro 2
  25. */
  26.  
  27.  
  28. //============================================================================
  29. //----------------------------------------------------------------------------
  30. //                                SetUpTakeDown.c
  31. //----------------------------------------------------------------------------
  32. //============================================================================
  33.  
  34. // The below functions are grouped here becuase they are only called once when…
  35. // Glypha either starts up or quits.
  36.  
  37. #include "G4Externs.h"
  38. #include <Palettes.h>                    // Need "Palettes.h" for the depth calls.
  39. #include <Fonts.h>
  40.  
  41. #define kHandPictID                128        // These are all the resource ID's for…
  42. #define kHandMaskID                129        // the various PICT's were going to…
  43. #define kBackgroundPictID        130        // load up into offscreen pixmaps and…
  44. #define kHelpPictID                131        // offscreen bitmaps.
  45. #define kObeliskPictID            134
  46. #define kPlayerPictID            135
  47. #define kPlayerMaskID            136
  48. #define kNumberPictID            137
  49. #define kIdlePictID                138
  50. #define kEnemyWalkPictID        139
  51. #define kEnemyFlyPictID            140
  52. #define kEnemyWalkMaskID        141
  53. #define kEnemyFlyMaskID            142
  54. #define kFlamePictID            143
  55. #define kEggPictID                144
  56. #define kEggMaskID                145
  57. #define kPlatformPictID            146
  58. #define kEyePictID                147
  59. #define kEyeMaskID                148
  60. #define kObeliskMaskPictID        149
  61. #define kBannerPictID            150
  62.  
  63.  
  64.  
  65. Boolean DoWeHaveColor (void);            // Prototypes to below functions that are…
  66. Boolean DoWeHaveSystem605 (void);        // called locally.  These aren't really…
  67. short WhatsOurDepth (void);                // necessary, but I don't enjoy relying on…
  68. Boolean CanWeDisplay8Bit (GDHandle);    // the compiler to second guess me.
  69. void SwitchToDepth (short, Boolean);
  70.  
  71. void MyInitAttributes( DSpContextAttributes *inAttributes );
  72.  
  73. short        wasDepth;                    // Only global variable defined here.
  74.  
  75. #if GENERATINGPOWERPC
  76.     DSpContextAttributes gTheContextAttributes;
  77.     DSpContextReference gTheContext;
  78. #endif
  79.                                         // Other global variables defined elsewhere.
  80. extern    Rect        mainWindowRect, backSrcRect, workSrcRect, obSrcRect, playerSrcRect;
  81. extern    Rect        numberSrcRect, idleSrcRect, enemyWalkSrcRect, enemyFlySrcRect;
  82. extern    Rect        obeliskRects[4], playerRects[11], numbersSrc[11], numbersDest[11];
  83. extern    Rect        platformRects[6], touchDownRects[6], enemyRects[24], handSrcRect;
  84. extern    Rect        flameSrcRect, flameDestRects[2], flameRects[4], platformCopyRects[9];
  85. extern    Rect        enemyInitRects[5], eggSrcRect, platformSrcRect, helpSrcRect;
  86. extern    Rect        handRects[2], grabZone, eyeSrcRect, bannerSrcRect, eyeRects[4];
  87. extern    GDHandle    thisGDevice;
  88. extern    CGrafPtr    origBackSrcMap, backSrcMap, workSrcMap, obeliskSrcMap, playerSrcMap;
  89. extern    CGrafPtr    numberSrcMap, idleSrcMap, enemyWalkSrcMap, enemyFlySrcMap;
  90. extern    CGrafPtr    flameSrcMap, eggSrcMap, platformSrcMap, helpSrcMap, handSrcMap;
  91. extern    CGrafPtr    eyeSrcMap, bannerSrcMap;
  92. extern    GrafPtr        playerMaskMap, enemyWalkMaskMap, enemyFlyMaskMap, eggMaskMap;
  93. extern    GrafPtr        handMaskMap, eyeMaskMap, obeliskMaskMap;
  94. extern    MenuHandle    appleMenu, gameMenu, optionsMenu;
  95. extern    long        theScore, wasTensOfThousands;
  96. extern    short        numLedges, beginOnLevel, levelOn, livesLeft;
  97. extern    Boolean        quitting, playing, pausing, switchedOut, canPlay, whichList;
  98. extern    Boolean        helpOpen, scoresOpen, openTheScores;
  99.  
  100.  
  101. //==============================================================  Functions
  102. //--------------------------------------------------------------  ToolBoxInit
  103.  
  104. // Here's the first function you ever call in Glypha (or any Mac program for…
  105. // that matter).  The calls herein MUST be called before you do anything else.
  106. // Otherwise, you'll get all sorts of System Errors.
  107.  
  108. void ToolBoxInit (void)
  109. {
  110.     InitGraf(&qd.thePort);        // Initialize QuickDraw variables for our program.
  111.     InitFonts();                // Initialize fonts.
  112.     FlushEvents(everyEvent, 0);    // Clear event queue of any pending events.
  113.     InitWindows();                // Initialize the Window Manager.
  114.     InitMenus();                // Ditto for the Menu Manager.
  115.     TEInit();                    // blah, blah Text Edit.
  116.     InitDialogs(0L);            // blah, blah Dialog Manager.
  117.     InitCursor();                // Set the cursor to the arrow cursor and init.
  118.     
  119.     MaxApplZone();                // Grab application memory.
  120.     
  121.     MoreMasters();                // Allocate a block of master pointers.
  122.     MoreMasters();                // And allocate more.
  123.     MoreMasters();                // And more.
  124.     MoreMasters();                // Hey, lets do it again too.
  125.     
  126.     switchedOut = FALSE;        // We "should" be the foreground app at this time.
  127.     GetDateTime((unsigned long *)&qd.randSeed);        // Randomize random seed.
  128. }
  129.  
  130. //--------------------------------------------------------------  DoWeHaveColor  
  131.  
  132. // Simple function that returns TRUE if we're running on a Mac that…
  133. // is running Color Quickdraw.
  134.  
  135. Boolean DoWeHaveColor (void)
  136. {
  137.     SysEnvRec        thisWorld;
  138.     
  139.     SysEnvirons(2, &thisWorld);        // Call the old SysEnvirons() function.
  140.     return (thisWorld.hasColorQD);    // And return whether it has Color QuickDraw.
  141. }
  142.  
  143. //--------------------------------------------------------------  DoWeHaveSystem605  
  144.  
  145. // Another simple "environment" function.  Returns TRUE if the Mac we're running…
  146. // on has System 6.0.5 or more recent.  (6.0.5 introduced the ability to switch…
  147. // color depths.)
  148.  
  149. Boolean DoWeHaveSystem605 (void)
  150. {
  151.     SysEnvRec        thisWorld;
  152.     Boolean            haveIt;
  153.     
  154.     SysEnvirons(2, &thisWorld);        // Call the old SysEnvirons() function.
  155.     if (thisWorld.systemVersion >= 0x0605)
  156.         haveIt = TRUE;                // Check the System version for 6.0.5…
  157.     else                            // or more recent
  158.         haveIt = FALSE;
  159.     return (haveIt);
  160. }
  161.  
  162. //--------------------------------------------------------------  WhatsOurDepth  
  163.  
  164. // Function returns the current bit depth.  For example, 4 = 16 colors, 8 = 256…
  165. // colors.  Note, this function assumes System 6.0.5 or more recent and Color…
  166. // Quickdraw capable.  You should haved called the previous two functions before…
  167. // attempting this call.
  168.  
  169. short WhatsOurDepth (void)
  170. {
  171.     short            thisDepth;
  172.     char            wasState;
  173.     
  174.     if (thisGDevice != 0L)                            // Make sure we have device handle.
  175.     {
  176.         wasState = HGetState((Handle)thisGDevice);    // Remember the handle's state.
  177.         HLock((Handle)thisGDevice);                    // Lock the device handle down.
  178.                                                     // Get it's depth (pixelSize).
  179.         thisDepth = (**(**thisGDevice).gdPMap).pixelSize;
  180.         HSetState((Handle)thisGDevice, wasState);    // Restore handle's state.
  181.     }
  182.     else
  183.         RedAlert("\pUnknown Error.");                // Post generic error message.
  184.     
  185.     return (thisDepth);                                // Return screen depth.
  186. }
  187.  
  188. //--------------------------------------------------------------  CanWeDisplay8Bit  
  189.  
  190. // Simple function that returns TRUE if the current device (monitor) is…
  191. // capable of displaying 256 colors (or grays).  This function, the one above,…
  192. // and many following functions assume we have System 6.0.5 or more recent and…
  193. // are capable of Color QuickDraw.
  194.  
  195. Boolean CanWeDisplay8Bit (GDHandle theDevice)
  196. {
  197.     short        canDepth;
  198.     Boolean        canDo;
  199.     
  200.     canDo = FALSE;        // Assume intially that we can't display 8 bit.
  201.                         // Call HasDepth() to see if monitor supports 8 bit.
  202.     canDepth = HasDepth(theDevice, 8, 1, 0);
  203.     if (canDepth != 0)    // If HasDepth() returned anything other than 0…
  204.         canDo = TRUE;    // we can indeed switch it to 8 bit.
  205.     
  206.     return (canDo);        // Return the result.
  207. }
  208.  
  209. //--------------------------------------------------------------  SwitchToDepth
  210.  
  211. // This handy function forces the device (monitor) in question to switch…
  212. // to a specific depth.  We'll call this function if we need to switch to…
  213. // 8-bit (256 colors).  We should have called the above function first in…
  214. // order to be sure that we CAN in fact switch this monitor to 8-bit.
  215.  
  216. void SwitchToDepth (short newDepth, Boolean doColor)
  217. {
  218.     OSErr            theErr;
  219.     short            colorFlag;
  220.     char            tagByte;
  221.     
  222.     if (doColor)                    // We can switch to either colors or grays.
  223.         colorFlag = 1;
  224.     else
  225.         colorFlag = 0;
  226.     
  227.     if (thisGDevice != 0L)            // Make sure we have a device.
  228.     {                                // Remember handle's state (as usual).
  229.         tagByte = HGetState((Handle)thisGDevice);
  230.         HLock((Handle)thisGDevice);    // Lock it.
  231.                                     // Call SetDepth() (System 6.0.5 or more recent).
  232.         theErr = SetDepth(thisGDevice, newDepth, 1, colorFlag);
  233.                                     // Restore handle's state.
  234.         HSetState((Handle)thisGDevice, tagByte);
  235.         if (theErr != noErr)        // If call failed, go to error dialog.
  236.             RedAlert("\pUnknown Error.");
  237.     }
  238.     else                            // Call error dialog if no device handle.
  239.         RedAlert("\pUnknown Error.");
  240. }
  241.  
  242. //--------------------------------------------------------------  CheckEnvirons
  243.  
  244. // This is the "wrapper" function that calls all the above functions.
  245. // After calling ToolBoxInit(), Glypha will call this function to see…
  246. // if the current Mac we're running on is capable of running Glypha.
  247.  
  248. void CheckEnvirons (void)
  249. {    
  250. #if GENERATINGPOWERPC
  251.     OSStatus theError;
  252.     
  253.     // DSp_SetDebugMode( true );
  254.     
  255.     // 640x480x8
  256.     MyInitAttributes( &gTheContextAttributes );
  257.     gTheContextAttributes.displayWidth            = 640;
  258.     gTheContextAttributes.displayHeight            = 480;
  259.     gTheContextAttributes.colorNeeds            = kDSpColorNeeds_Require;
  260.     gTheContextAttributes.backBufferDepthMask    = kDSpDepthMask_8;
  261.     gTheContextAttributes.displayDepthMask        = kDSpDepthMask_8;
  262.     gTheContextAttributes.backBufferBestDepth    = 8;
  263.     gTheContextAttributes.displayBestDepth        = 8;
  264.     theError = DSpFindBestContext( &gTheContextAttributes, &gTheContext );
  265.     if( theError )
  266.         RedAlert("\pUnable to find a suitable device\n");
  267.     
  268.     FindOurDevice();
  269.     
  270. #else        
  271.     if (!DoWeHaveColor())            // We absolutely need Color QuickDraw.
  272.         RedAlert("\pGlypha IV only runs in 256 colors.");
  273.     
  274.     if (!DoWeHaveSystem605())        // We absolutely need System 6.0.5. or more recent.
  275.         RedAlert("\pGlypha IV requires System 6.0.5 or better to run.");
  276.     
  277.     FindOurDevice();
  278.     
  279.     wasDepth = WhatsOurDepth();        // Find out our monitor's depth.
  280.     if (wasDepth != 8)                // If it's not 8-bit we'll need to switch depths.
  281.     {                                // Test 1st to see if monitor capable of 8-bit.
  282.         if (CanWeDisplay8Bit(thisGDevice))
  283.             SwitchToDepth(8, TRUE);    // If so, switch to 256 colors.
  284.         else                        // If not, we have to quit.
  285.             RedAlert("\pGlypha IV only runs in 256 colors.");
  286.     }
  287. #endif
  288. }
  289.  
  290. //--------------------------------------------------------------  OpenMainWindow
  291.  
  292. // This is a simple function that merely opens up a large black window and…
  293. // centers it in the monitor.  It assumes a 'WIND' (window) resource, which if you…
  294. // look at the resource file in ResEdit, you'll find it also has a 'WCTB'…
  295. // (window color table) resource.  The 'WCTB' resource specifies a content…
  296. // color of black - thus this window comes up black.
  297.  
  298. void OpenMainWindow (void)
  299. {
  300. #if GENERATINGPOWERPC
  301.     OSStatus theError;
  302.     
  303.     theError = DSpContext_Reserve( gTheContext, &gTheContextAttributes );
  304.     if( theError )
  305.         RedAlert("\pUnable to create the display!");
  306.  
  307.     theError = DSpContext_FadeGammaOut( NULL, NULL );    
  308.     if( theError )
  309.         RedAlert("\pUnable to fade the display!");
  310.  
  311.     theError = DSpContext_SetState( gTheContext, kDSpContextState_Active );
  312.     if( theError )
  313.         RedAlert("\pUnable to set the display!");
  314.  
  315.     // this is our fake main window, it is really a CGrafPtr so don't try to
  316.     // use it with the Window Manager, and DON'T try to dispose of it.  In
  317.     // a page flipping scenario, it would change with every call to SwapDisplayBuffers(),
  318.     // but since Glypha is designed to work with DoubleBuffering we know the front
  319.     // buffer will remain the same.
  320.     SetRect(&mainWindowRect, 0, 0, 640, 480);            // Our window size.
  321.     
  322. #else
  323.     SetRect(&mainWindowRect, 0, 0, 640, 460);            // Our window size.
  324.     mainWindow = GetNewCWindow(128, 0L, kPutInFront);    // Load window from resource.
  325.                                                         // Make it the right size.
  326.     SizeWindow((GrafPtr)mainWindow, mainWindowRect.right - mainWindowRect.left, 
  327.             mainWindowRect.bottom - mainWindowRect.top, FALSE);
  328.                                                         // Center the window.
  329.     MoveWindow((GrafPtr)mainWindow, (qd.screenBits.bounds.right - 640) / 2, 
  330.             ((qd.screenBits.bounds.bottom - 480) / 2) + LMGetMBarHeight(), TRUE);
  331.     ShowWindow((GrafPtr)mainWindow);                    // Now display it.
  332.     SetPort((GrafPtr)mainWindow);                        // Make its port current.
  333.     ClipRect(&mainWindowRect);                            // Set its clip region.
  334.     CopyRgn(mainWindow->clipRgn, mainWindow->visRgn);    // Set its visRgn.
  335.     ForeColor(blackColor);                                // Set its pen color to black.
  336.     BackColor(whiteColor);                                // Set background color white.
  337. #endif
  338. }
  339.  
  340. //--------------------------------------------------------------  InitMenubar
  341.  
  342. // This function loads up the menus and displays the menu bar.
  343.  
  344. void InitMenubar (void)
  345. {
  346.     appleMenu = GetMenu(128);        // Get the Apple menu (About…).
  347.     if (appleMenu == 0L)            // See that it loaded okay.
  348.         RedAlert("\pCouldn't Load Menus Error");
  349.     AppendResMenu(appleMenu, 'DRVR');    // Add Desk Accesories.
  350.     InsertMenu(appleMenu, 0);        // Add to menu bar.
  351.     
  352.     gameMenu = GetMenu(129);        // Next load the Game menu.
  353.     if (gameMenu == 0L)                // Make sure it loaded as well.
  354.         RedAlert("\pCouldn't Load Menus Error");
  355.     InsertMenu(gameMenu, 0);        // And add it next to the menu bar.
  356.     
  357.     optionsMenu = GetMenu(130);        // Finally load the Options menu.
  358.     if (optionsMenu == 0L)
  359.         RedAlert("\pCouldn't Load Menus Error");
  360.     InsertMenu(optionsMenu, 0);        // And insert it.
  361.     
  362.     DrawMenuBar();                    // Now display the menu bar.
  363. }
  364.  
  365. //--------------------------------------------------------------  InitVariables
  366.  
  367. // This function is called only once.  It initializes all the global variables…
  368. // used by Glypha.  It may not in fact be necessary to initialize many of these…
  369. // (your compiler should ensure that all globals are set to zero when your app…
  370. // launches), but it's a good idea to NEVER TRUST YOUR COMPILER.
  371.  
  372. void InitVariables (void)
  373. {
  374.     short        i;
  375.     OSStatus    theError;
  376.         
  377.     quitting = FALSE;    // I won't describe every one of these, many are…
  378.     playing = FALSE;    // self explanatory.  Suffice it to say that first…
  379.     pausing = FALSE;    // I'm initializing all the Boolean variables.
  380.     canPlay = FALSE;
  381.     whichList = TRUE;
  382.     helpOpen = FALSE;
  383.     scoresOpen = FALSE;
  384.     openTheScores = FALSE;
  385.     
  386.     numLedges = 3;                    // Number of ledges in the "arena".
  387.     beginOnLevel = 1;                // First level to begin playing.
  388.     levelOn = 0;                    // Level number player is on.
  389.     livesLeft = kInitNumLives;        // Number of player lives.
  390.     theScore = 0L;                    // Player's score (notice it's a long!).
  391.     wasTensOfThousands = 0L;        // For tracking when player gets an extra life.
  392.     GenerateLightning(320, 240);    // Initialize a lightning bolt.
  393.     
  394.     backSrcRect = mainWindowRect;    // Create background offscreen pixmap.
  395.     ZeroRectCorner(&backSrcRect);
  396.     backSrcMap = 0L;
  397.     CreateOffScreenPixMap(&backSrcRect, &backSrcMap);
  398.     LoadGraphic(kBackgroundPictID);
  399.     
  400.     origBackSrcMap = 0L;
  401.     CreateOffScreenPixMap(&backSrcRect, &origBackSrcMap);
  402.     LoadGraphic(kBackgroundPictID);
  403.  
  404. #if GENERATINGPOWERPC
  405.     theError = DSpContext_GetBackBuffer( gTheContext, kDSpBufferKind_Normal, &workSrcMap );
  406.     if( theError )
  407.     {
  408.         DSpContext_Release( gTheContext );
  409.         RedAlert("\pUnable to get back buffer");
  410.     }
  411. #else    
  412.     workSrcRect = mainWindowRect;    // Create "work" offscreen pixmap.
  413.     ZeroRectCorner(&workSrcRect);
  414.     workSrcMap = 0L;
  415.     CreateOffScreenPixMap(&workSrcRect, &workSrcMap);
  416. #endif
  417.  
  418.     SetRect(&obSrcRect, 0, 0, 20, 418);
  419.     obeliskSrcMap = 0L;                // Create pixmap to hold "obelisk" graphics.
  420.     CreateOffScreenPixMap(&obSrcRect, &obeliskSrcMap);
  421.     LoadGraphic(kObeliskPictID);
  422.     SetRect(&obeliskRects[0], 0, 0, 20, 209);
  423.     OffsetRect(&obeliskRects[0], 0, 0);
  424.     SetRect(&obeliskRects[1], 0, 0, 20, 209);
  425.     OffsetRect(&obeliskRects[1], 0, 209);
  426.     SetRect(&obeliskRects[2], 0, 0, 20, 209);
  427.     OffsetRect(&obeliskRects[2], 161, 250);
  428.     SetRect(&obeliskRects[3], 0, 0, 20, 209);
  429.     OffsetRect(&obeliskRects[3], 457, 250);
  430.     
  431.     obeliskMaskMap = 0L;                // Create pixmap to hold "obelisk" mask
  432.     CreateOffScreenBitMap(&obSrcRect, &obeliskMaskMap);
  433.     LoadGraphic(kObeliskMaskPictID);
  434.     
  435.     
  436.     SetRect(&playerSrcRect, 0, 0, 48, 436);
  437.     playerSrcMap = 0L;                // Create pixmap to hold "player" graphics.
  438.     CreateOffScreenPixMap(&playerSrcRect, &playerSrcMap);
  439.     LoadGraphic(kPlayerPictID);
  440.     playerMaskMap = 0L;
  441.     CreateOffScreenBitMap(&playerSrcRect, &playerMaskMap);
  442.     LoadGraphic(kPlayerMaskID);
  443.     
  444.     SetRect(&enemyWalkSrcRect, 0, 0, 48, 576);
  445.     enemyWalkSrcMap = 0L;            // Create pixmap to hold "enemy" graphics.
  446.     CreateOffScreenPixMap(&enemyWalkSrcRect, &enemyWalkSrcMap);
  447.     LoadGraphic(kEnemyWalkPictID);
  448.     enemyWalkMaskMap = 0L;
  449.     CreateOffScreenBitMap(&enemyWalkSrcRect, &enemyWalkMaskMap);
  450.     LoadGraphic(kEnemyWalkMaskID);
  451.     SetRect(&enemyFlySrcRect, 0, 0, 64, 480);
  452.     enemyFlySrcMap = 0L;
  453.     CreateOffScreenPixMap(&enemyFlySrcRect, &enemyFlySrcMap);
  454.     LoadGraphic(kEnemyFlyPictID);
  455.     enemyFlyMaskMap = 0L;
  456.     CreateOffScreenBitMap(&enemyFlySrcRect, &enemyFlyMaskMap);
  457.     LoadGraphic(kEnemyFlyMaskID);
  458.     for (i = 0; i < 12; i++)
  459.     {                                // Set up enemy source rectangles.
  460.         SetRect(&enemyRects[i], 0, 0, 48, 48);
  461.         OffsetRect(&enemyRects[i], 0, 48 * i);
  462.     }
  463.     for (i = 0; i < 12; i++)
  464.     {
  465.         SetRect(&enemyRects[i + 12], 0, 0, 64, 40);
  466.         OffsetRect(&enemyRects[i + 12], 0, 40 * i);
  467.     }
  468.     SetRect(&enemyInitRects[0], 0, 0, 48, 1);
  469.     OffsetRect(&enemyInitRects[0], 72, 284);
  470.     SetRect(&enemyInitRects[1], 0, 0, 48, 1);
  471.     OffsetRect(&enemyInitRects[1], 520, 284);
  472.     SetRect(&enemyInitRects[2], 0, 0, 48, 1);
  473.     OffsetRect(&enemyInitRects[2], 72, 105);
  474.     SetRect(&enemyInitRects[3], 0, 0, 48, 1);
  475.     OffsetRect(&enemyInitRects[3], 520, 105);
  476.     SetRect(&enemyInitRects[4], 0, 0, 48, 1);
  477.     OffsetRect(&enemyInitRects[4], 296, 190);
  478.     
  479.     SetRect(&eggSrcRect, 0, 0, 24, 24);
  480.     eggSrcMap = 0L;                    // Create pixmap to hold "egg" graphics.
  481.     CreateOffScreenPixMap(&eggSrcRect, &eggSrcMap);
  482.     LoadGraphic(kEggPictID);
  483.     eggMaskMap = 0L;
  484.     CreateOffScreenBitMap(&eggSrcRect, &eggMaskMap);
  485.     LoadGraphic(kEggMaskID);
  486.  
  487.     bannerSrcMap = 0L;                    // Create pixmap to hold banner graphics.
  488.     SetRect(&bannerSrcRect,0,0,1280,20);
  489.     CreateOffScreenPixMap(&bannerSrcRect, &bannerSrcMap);
  490.     LoadGraphic(kBannerPictID);
  491.     
  492.     SetRect(&eyeSrcRect, 0, 0, 48, 124);
  493.     eyeSrcMap = 0L;                    // Create pixmap to hold "eye" graphics.
  494.     CreateOffScreenPixMap(&eyeSrcRect, &eyeSrcMap);
  495.     LoadGraphic(kEyePictID);
  496.     eyeMaskMap = 0L;
  497.     CreateOffScreenBitMap(&eyeSrcRect, &eyeMaskMap);
  498.     LoadGraphic(kEyeMaskID);
  499.     for (i = 0; i < 4; i++)
  500.     {
  501.         SetRect(&eyeRects[i], 0, 0, 48, 31);
  502.         OffsetRect(&eyeRects[i], 0, i * 31);
  503.     }
  504.     
  505.     SetRect(&handSrcRect, 0, 0, 56, 114);
  506.     handSrcMap = 0L;                // Create pixmap to hold "mummy hand" graphics.
  507.     CreateOffScreenPixMap(&handSrcRect, &handSrcMap);
  508.     LoadGraphic(kHandPictID);
  509.     handMaskMap = 0L;
  510.     CreateOffScreenBitMap(&handSrcRect, &handMaskMap);
  511.     LoadGraphic(kHandMaskID);
  512.     SetRect(&handRects[0], 0, 0, 56, 57);
  513.     OffsetRect(&handRects[0], 0, 0);
  514.     SetRect(&handRects[1], 0, 0, 56, 57);
  515.     OffsetRect(&handRects[1], 0, 57);
  516.     SetRect(&grabZone, 0, 0, 96, 108);
  517.     OffsetRect(&grabZone, 48, 352);
  518.     
  519.     SetRect(&idleSrcRect, 0, 0, 48, 48);
  520.     idleSrcMap = 0L;                // Create pixmap to hold "shielded player".
  521.     CreateOffScreenPixMap(&idleSrcRect, &idleSrcMap);
  522.     LoadGraphic(kIdlePictID);
  523.     
  524.     SetRect(&flameSrcRect, 0, 0, 16, 64);
  525.     flameSrcMap = 0L;                // Create pixmap to hold "torch" graphics.
  526.     CreateOffScreenPixMap(&flameSrcRect, &flameSrcMap);
  527.     LoadGraphic(kFlamePictID);
  528.     SetRect(&flameDestRects[0], 0, 0, 16, 16);
  529.     OffsetRect(&flameDestRects[0], 87, 325);
  530.     SetRect(&flameDestRects[1], 0, 0, 16, 16);
  531.     OffsetRect(&flameDestRects[1], 535, 325);
  532.     for (i = 0; i < 4; i++)
  533.     {
  534.         SetRect(&flameRects[i], 0, 0, 16, 16);
  535.         OffsetRect(&flameRects[i], 0, i * 16);
  536.     }
  537.     
  538.     SetRect(&numberSrcRect, 0, 0, 8, 121);
  539.     numberSrcMap = 0L;                // Create pixmap to hold "score numbers".
  540.     CreateOffScreenPixMap(&numberSrcRect, &numberSrcMap);
  541.     LoadGraphic(kNumberPictID);
  542.     for (i = 0; i < 11; i++)
  543.     {
  544.         SetRect(&numbersSrc[i], 0, 0, 8, 11);
  545.         OffsetRect(&numbersSrc[i], 0, 11 * i);
  546.     }
  547.     SetRect(&numbersDest[0], 0, 0, 8, 11);    // # of lives digit 1
  548.     OffsetRect(&numbersDest[0], 229, 443);
  549.     SetRect(&numbersDest[1], 0, 0, 8, 11);    // # of lives digit 2
  550.     OffsetRect(&numbersDest[1], 237, 443);
  551.     SetRect(&numbersDest[2], 0, 0, 8, 11);    // score digit 1
  552.     OffsetRect(&numbersDest[2], 293, 443);
  553.     SetRect(&numbersDest[3], 0, 0, 8, 11);    // score digit 2
  554.     OffsetRect(&numbersDest[3], 301, 443);
  555.     SetRect(&numbersDest[4], 0, 0, 8, 11);    // score digit 3
  556.     OffsetRect(&numbersDest[4], 309, 443);
  557.     SetRect(&numbersDest[5], 0, 0, 8, 11);    // score digit 4
  558.     OffsetRect(&numbersDest[5], 317, 443);
  559.     SetRect(&numbersDest[6], 0, 0, 8, 11);    // score digit 5
  560.     OffsetRect(&numbersDest[6], 325, 443);
  561.     SetRect(&numbersDest[7], 0, 0, 8, 11);    // score digit 6
  562.     OffsetRect(&numbersDest[7], 333, 443);
  563.     SetRect(&numbersDest[8], 0, 0, 8, 11);    // # of level digit 1
  564.     OffsetRect(&numbersDest[8], 381, 443);
  565.     SetRect(&numbersDest[9], 0, 0, 8, 11);    // # of level digit 2
  566.     OffsetRect(&numbersDest[9], 389, 443);
  567.     SetRect(&numbersDest[10], 0, 0, 8, 11);    // # of level digit 3
  568.     OffsetRect(&numbersDest[10], 397, 443);
  569.     
  570.     SetRect(&playerRects[0], 0, 0, 48, 37);
  571.     OffsetRect(&playerRects[0], 0, 0);
  572.     SetRect(&playerRects[1], 0, 0, 48, 37);
  573.     OffsetRect(&playerRects[1], 0, 37);
  574.     SetRect(&playerRects[2], 0, 0, 48, 37);
  575.     OffsetRect(&playerRects[2], 0, 74);
  576.     SetRect(&playerRects[3], 0, 0, 48, 37);
  577.     OffsetRect(&playerRects[3], 0, 111);
  578.     SetRect(&playerRects[4], 0, 0, 48, 48);
  579.     OffsetRect(&playerRects[4], 0, 148);
  580.     SetRect(&playerRects[5], 0, 0, 48, 48);
  581.     OffsetRect(&playerRects[5], 0, 196);
  582.     SetRect(&playerRects[6], 0, 0, 48, 48);
  583.     OffsetRect(&playerRects[6], 0, 244);
  584.     SetRect(&playerRects[7], 0, 0, 48, 48);
  585.     OffsetRect(&playerRects[7], 0, 292);
  586.     SetRect(&playerRects[8], 0, 0, 48, 37);        // falling bones rt.
  587.     OffsetRect(&playerRects[8], 0, 340);
  588.     SetRect(&playerRects[9], 0, 0, 48, 37);        // falling bones lf.
  589.     OffsetRect(&playerRects[9], 0, 377);
  590.     SetRect(&playerRects[10], 0, 0, 48, 22);    // pile of bones
  591.     OffsetRect(&playerRects[10], 0, 414);
  592.     
  593.     SetRect(&platformSrcRect, 0, 0, 191, 192);
  594.     platformSrcMap = 0L;    // Create pixmap to hold "platform" graphic.
  595.     CreateOffScreenPixMap(&platformSrcRect, &platformSrcMap);
  596.     LoadGraphic(kPlatformPictID);
  597.     for (i = 0; i < 6; i++)
  598.     {
  599.         SetRect(&platformCopyRects[i], 0, 0, 191, 32);
  600.         OffsetRect(&platformCopyRects[i], 0, 32 * i);
  601.     }
  602.     SetRect(&platformCopyRects[6], 233, 190, 424, 222);
  603.     SetRect(&platformCopyRects[7], 0, 105, 191, 137);
  604.     SetRect(&platformCopyRects[8], 449, 105, 640, 137);
  605.                             // These are the platforms.  See diagram for numbering.
  606.     SetRect(&platformRects[0], 206, 424, 433, 438);        //_______________
  607.     SetRect(&platformRects[1], -256, 284, 149, 298);    //
  608.     SetRect(&platformRects[2], 490, 284, 896, 298);        //--3--     --4--
  609.     SetRect(&platformRects[3], -256, 105, 149, 119);    //     --5--
  610.     SetRect(&platformRects[4], 490, 105, 896, 119);        //--1--     --2--
  611.     SetRect(&platformRects[5], 233, 190, 407, 204);        //_____--0--_____
  612.     
  613.     for (i = 0; i < 6; i++)
  614.     {                        // "Hot rects" to sense if player landing on platform.
  615.         touchDownRects[i] = platformRects[i];
  616.         touchDownRects[i].left += 23;
  617.         touchDownRects[i].right -= 23;
  618.         touchDownRects[i].bottom = touchDownRects[i].top;
  619.         touchDownRects[i].top = touchDownRects[i].bottom - 11;
  620.     }
  621.     
  622.     SetRect(&helpSrcRect, 0, 0, 231, 398);
  623.     helpSrcMap = 0L;        // Create pixmap to hold "help screen" graphic.
  624.     CreateOffScreenPixMap(&helpSrcRect, &helpSrcMap);
  625.     LoadGraphic(kHelpPictID);
  626.  
  627. }
  628.  
  629. //--------------------------------------------------------------  ShutItDown
  630.  
  631. #define kFadeSteps        25
  632. #define kFadeStepSize    (100/kFadeSteps)
  633.  
  634. void ShutItDown (void)
  635. {
  636. #if GENERATINGPOWERPC
  637.     unsigned long theFinalTick;
  638.     
  639.     DSpContext_FadeGammaOut( NULL, NULL );
  640.     DSpContext_SetState( gTheContext, kDSpContextState_Inactive );
  641.     
  642.     Delay( 30, &theFinalTick );
  643.  
  644.     DSpContext_FadeGammaIn( NULL, NULL );
  645.     
  646.     DSpContext_Release( gTheContext );
  647.     DSpShutdown();
  648.     
  649. #else
  650.     if (wasDepth != WhatsOurDepth())    // Need only switch if wasn't 8-bit.
  651.         SwitchToDepth(wasDepth, TRUE);    // Switch back to out "old" depth.
  652. #endif
  653. }
  654.  
  655. /*
  656. ********************************************************************************
  657. **
  658. ** Name: MyInitAttributes
  659. **
  660. ** Description:
  661. **
  662. **    Initialize a context attributes structure so that there is no garbage
  663. **    data in it.  This is important to do because DS will return an error
  664. **    if some fields are set incorrectly (including the "reserved" fields not
  665. **    being set to zero), and some things can actually cause a crash (such
  666. **    as a bogus color table handle).
  667. **
  668. ********************************************************************************
  669. */
  670. void
  671. MyInitAttributes(
  672.     DSpContextAttributes *inAttributes        /* attr structure to init */
  673. )
  674. {
  675.     if( NULL == inAttributes )
  676.         DebugStr("\pStimpy! You Idiot!");
  677.         
  678.     inAttributes->frequency                    = 0;
  679.     inAttributes->displayWidth                = 0;
  680.     inAttributes->displayHeight                = 0;
  681.     inAttributes->reserved1                    = 0;
  682.     inAttributes->reserved2                    = 0;
  683.     inAttributes->colorNeeds                = 0;
  684.     inAttributes->colorTable                = NULL;
  685.     inAttributes->contextOptions            = 0;
  686.     inAttributes->backBufferDepthMask        = 0;
  687.     inAttributes->displayDepthMask            = 0;
  688.     inAttributes->backBufferBestDepth        = 0;
  689.     inAttributes->displayBestDepth            = 0;
  690.     inAttributes->pageCount                    = 0;
  691.     inAttributes->gameMustConfirmSwitch        = false;
  692.     inAttributes->reserved3[0]                = 0;
  693.     inAttributes->reserved3[1]                = 0;
  694.     inAttributes->reserved3[2]                = 0;
  695.     inAttributes->reserved3[3]                = 0;
  696. }
  697.